import { observable, action, toJS } from 'mobx';
import { message } from 'antd';
import * as Apis from '../apis/customerRightMenu';

export default class BusinessCardStore {
    @observable businessInfoData = {} ; // 工商

    // 获取工商信息
    @action
    getBusinessInfo = (params) => {
      const that = this;
      Apis.getBusinessInfo(toJS(params)).then((data) => {
        if (data.status == 'success') {
          const datas = data.datas;
          if (datas.fromCache) { // 取的缓存的数据
            that.businessInfoData = datas.businessInfoData.data;
            Apis.saveBusinessLog({ ...toJS(params), requesttype: 1 }).then((data) => { // 保存日志
              // return true;
            });
          } else {
            const res = datas.businessInfoData;
            if (res.status == '200') {
              that.businessInfoData = res.data;
              if (datas.isCache == '1') { // 缓存数据
                Apis.cacheBusinessInfo({ ...toJS(params), data: JSON.stringify(res) }).then((data) => {
                  // return true;
                });
              }
              Apis.saveBusinessLog({ ...toJS(params), requesttype: 0 }).then((data) => { // 保存日志
                // return true;
              });
            } else {
              message.error(res.message);
            }
          }
        } else {
          message.error(data.msgcode);
        }
      });
    }
}

